package com.neusoft.blog.controller;

import com.neusoft.blog.bean.RespBean;
import com.neusoft.blog.bean.UserUtile;
import com.neusoft.blog.bean.Userinfo;
import com.neusoft.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;
//    @PostMapping("/login")
//    public Userinfo login(@RequestParam("loginname") String username, String password){
//        return userService.login(username,password);
//    }
    @PostMapping("/login")
    public RespBean login(@RequestParam("loginname") String username, String password){
        Userinfo userinfo=userService.login(username,password);
        if(userinfo!=null){
            return RespBean.ok("登录成功",userinfo);
        }
        return RespBean.error("登录失败");
    }

    @GetMapping("/seletUser")
    public List<Userinfo> seletUser(){
        return  userService.seletUser();
    }
    @PutMapping("/updeteStatus")
    public RespBean updeteStatus(Boolean enabled,Integer id){
        return  userService.updeteStatus(enabled,id);
    }
    @GetMapping("/findUser")
    public UserUtile findUser(String loginname){
        return userService.findUser(loginname);
    }
    @DeleteMapping("/delUser/{id}")
    public  RespBean delUser (@PathVariable("id") Integer id ){
        return  userService.delUser(id);
    }
}
